//
//  SubscribeComicsCell.swift
//  Spookiness
//
//  Created by 腾億 on 2017/12/11.
//  Copyright © 2017年 tml. All rights reserved.
//

import UIKit

class SubscribeComicsCell: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.contentView.addSubview(self.iconView)
        self.contentView.addSubview(self.titleLabel)
        setUpSnap()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var iconView: UIImageView = {
       let imgV = UIImageView()
        imgV.contentMode = .scaleAspectFill
        imgV.clipsToBounds = true
        return imgV
    }()
    
    fileprivate lazy var titleLabel: UILabel = {
       let label = UILabel()
        label.textColor = UIColor.black
        label.font = UIFont.systemFont(ofSize: 14)
        return label
    }()
    
    fileprivate func setUpSnap() {
        self.titleLabel.snp.makeConstraints { (make) in
            make.right.left.bottom.equalToSuperview().inset(UIEdgeInsetsMake(0, 10, 0, 10))
            make.height.equalTo(25)
            make.bottom.equalToSuperview().offset(-10)
        }
        
        self.iconView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.bottom.equalTo(self.titleLabel.snp.top)
            
        }
    }
    
    var model: SubscribeComicsModel? {
        didSet{
            guard model != nil else {
                return
            }
            iconView.kf.setImage(urlString: model?.cover)
            titleLabel.text = model?.name ?? ""
        }
    }
    
}
